package roborally.script;

import java.util.ArrayList;
import java.util.List;

import exception.IllegalScriptSyntaxException;

import roborally.model.Robot;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * @author Joren VERSPEURT
 * @author Mathieu REYMOND
 * @version 3.0
 * 
 * The superclass for all ComposedConditions possible in RoboRally. This includes And, Not and Or.
 */
public abstract class ComposedCondition extends Condition {
	
	/**
	 * Creates a new ComposedCondition with a number of given sub-conditions, and a Robot this Condition will apply to.
	 * @param robot The Robot this Condition will apply to
	 * @param conditions The given sub-conditions.
	 * @throws IllegalScriptSyntaxException There need to be at least one subcondition to define a ComposedCondition.
	 */
	protected ComposedCondition(Robot robot, Condition... conditions) throws IllegalScriptSyntaxException{
		super(robot);
		this.conditions = new ArrayList<Condition>();
		for(Condition condition : conditions){
			if(condition != null) this.conditions.add(condition);
		}
		if(getConditions().isEmpty()) throw new IllegalScriptSyntaxException("You need at least one condition for this conditional statement.");
	}
	
	/**
	 * Get the list of sub-conditions of this ComposedCondition.
	 * @return The list of sub-conditions of this ComposedCondition.
	 */
	@Basic @Immutable
	public List<Condition> getConditions(){
		return conditions;
	}
	
	/**
	 * The list of sub-conditions of this ComposedCondition.
	 */
	protected final List<Condition> conditions;

}
